package cn.gson.crm.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.gson.crm.model.dao.PaymentRecordDAO;
import cn.gson.crm.model.pojo.Paymentrecord;
import cn.gson.crm.model.vo.PaymentPlanVO;
import cn.gson.crm.model.vo.PaymentRecordVO;

@Service
@Transactional
public class prService {
	@Autowired
	private PaymentRecordDAO pDao;

	public List<PaymentRecordVO> getAllPr(int page, int rows) {
		PageRequest pRequest = new PageRequest(page - 1, rows);
		List<Paymentrecord> listpo = pDao.getAllPr(pRequest);
		List<PaymentRecordVO> listvo = new ArrayList<>();
		for (Paymentrecord p : listpo) {
			listvo.add(returnPrVo(p));
		}
		return listvo;
	}

	public PaymentRecordVO returnPrVo(Paymentrecord p) {
		PaymentRecordVO pVo = new PaymentRecordVO(p.getPrId(), p.getPrCaiId(), p.getPrCaiName(), p.getPrCusId(),
				p.getPrCusName(), p.getPrMan(), p.getPrMoney(), p.getPrPayWay(), p.getPrPeriod(), p.getPrRemarks(),
				p.getPrTime());
		return pVo;
	}
	
	public Long count() {
		return pDao.count();
	}
	
	public void deletePr(Long id) {
		try {
			pDao.delete(id);
			throw new ServiceException();
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e);
		}
	}
}
